<jsp:include page="header.jsp" />
<jsp:include page="sidenav.jsp" />

<%@ page import="java.util.List" %>
<%@ page import="databean.PriceResearchBean" %>
<%
List<PriceResearchBean> products = (List<PriceResearchBean>) request.getAttribute("rs");
%>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load('visualization', '1', {'packages':['motionchart']});
google.setOnLoadCallback(drawChart);
function drawChart() {
  var data = new google.visualization.DataTable();
  data.addColumn('string', 'type');
  data.addColumn('date', 'Date');
  data.addColumn('number', 'value');
    data.addRows([
    <%
    int i=0;
    for(PriceResearchBean product:products){
    if(i++>0){
    %>
    ['Max',new Date (<%=product.getDate()%>),<%=product.getMaxSoldPrice()%>],
    ['Min',new Date (<%=product.getDate()%>),<%=product.getMinSoldPrice()%>],
    ['Aver',new Date (<%=product.getDate()%>),<%=product.getAverageSoldPrice()%>],
  <%}}%>
  ['Max',new Date (),<%=products.get(0).getMaxSoldPrice()%>],
  ['Min',new Date (),<%=products.get(0).getMinSoldPrice()%>],
  ['Aver',new Date (),<%=products.get(0).getAverageSoldPrice()%>]
    ]);
  var chart = new google.visualization.MotionChart(document.getElementById('chart'));
  var options = {};
options['state'] =
'{"colorOption":"_UNIQUE_COLOR","xZoomedIn":false,"sizeOption":"_UNISIZE","xLambda":1,"uniColorForNonSelected":false,"orderedByY":false,"playDuration":15000,"iconType":"BUBBLE","dimensions":{"iconDimensions":["dim0"]},"yAxisOption":"2","yZoomedDataMin":0.01,"xZoomedDataMin":0.01,"yZoomedDataMax":3200,"orderedByX":false,"nonSelectedAlpha":0.4,"time":"2009-07-21","duration":{"multiplier":1,"timeUnit":"D"},"showTrails":true,"yLambda":0,"yZoomedIn":false,"iconKeySettings":[],"xZoomedDataMax":3200,"xAxisOption":"2"};';

options['width'] = 550;
options['height'] = 400;
  chart.draw(data, options);
}
</script>  

<div id ="content">
    <h1>Perform Price Research - Result</h1>
	<hr />	
	<br><label>You searched:</label> <font color=#FF0000><span class="right">${rq}</span></font>
	<br><label>Time requested: </label><font color=#FF0000><span class="right">${timestamp}</span></font>
	<br><label>Processing time: </label><font color=#FF0000><span class="right">${processingTime}</span></font>
	<br><label>API remaining usage: </label><font color=#FF0000><span class="right">${callsRemaining}</span></font>
	<br />
	<br />
	<div id="chart"></div>
	<hr />
<% 
	boolean left = true;	
	for(PriceResearchBean product:products){
%>


	
<%
		if (left) {
%>



<div class ="result left half">

<label>Date: </label><span class="right"> <%=product.getDate()%></span><br>
<label>Total Sales: </label><span class="right">  <%=product.getTotalSales()%></span><br>
<label>Total Sold Items: </label><span class="right">  <%=product.getTotalSoldItems()%></span><br>
<label>Average Sold Price: </label><span class="right">  <%=product.getAverageSoldPrice()%></span><br>
<label>Max Sold Price: </label><span class="right">  <%=product.getMaxSoldPrice()%></span><br>
<label>Min Sold Price: </label><span class="right">  <%=product.getMinSoldPrice()%></span><br>

<br />
<hr />
</div>


<%
	left = false;
		} else {
%>


<div class = "result right half">

<label>Date: </label><span class="right"> <%=product.getDate()%></span><br>
<label>Total Sales: </label><span class="right">  <%=product.getTotalSales()%></span><br>
<label>Total Sold Items: </label><span class="right">  <%=product.getTotalSoldItems()%></span><br>
<label>Average Sold Price: </label><span class="right">  <%=product.getAverageSoldPrice()%></span><br>
<label>Max Sold Price: </label><span class="right">  <%=product.getMaxSoldPrice()%></span><br>
<label>Min Sold Price: </label><span class="right">  <%=product.getMinSoldPrice()%></span><br>

<br />
<hr />
</div>


<%
	left = true;
		}
%>

<%
}
%>

</div>
<jsp:include page="footer.jsp" />